<?php

declare(strict_types=1);

namespace app\admin\controller;

use app\common\model\system\PluginModel;
use app\common\service\FileService;
use app\common\service\ConfigService;

class Index extends Controller
{
    protected array $middleware = [
        'admin'     => ['except'     => ['index', 'initConfig']],
    ];

    public function index()
    {
        return redirect('https://shequ.chaopinvideo.cn/super');
    }

    /**
     * 后台初始化配置
     */
    public function initConfig()
    {

        $data = [
            // 系统上传方式 
            'upload_type' => ConfigService::get('system', 'upload_type', 'local'),
            // 控制台视图
            'dashboard_component' => ConfigService::get('website', 'dashboard_component', 'admin/views/dashboard/index'),
            // JWT
            'jwt' => [
                //JWT time to live
                'ttl'         => config('jwt.ttl', 3600),
                //Refresh time to live
                'refresh_ttl' => config('jwt.refresh_ttl'),
            ],
            // version
            'version' => config('admin.version'),
            // live
            'live' => PluginModel::where('name', 'liveStreaming')->where('status', 1)->value('id'),
            // card
            'card' => PluginModel::where('name', 'goodsCard')->where('status', 1)->value('id'),
            // activity
            'activity' => PluginModel::where('name', 'activity')->where('status', 1)->value('id'),
            // taobao
            'taobao' => PluginModel::where('name', 'taobao')->where('status', 1)->value('id'),
            // classify
            'classify' => PluginModel::where('name', 'goodsClassify')->where('status', 1)->value('id'),
            'theme' => [
               'color' => ConfigService::get('theme', 'color', '#000000'),
            ],
        ];
        $bq = '0,见闻间.,,见闻间 - 让社区以全新的方式喧起来！,Copyright © 2024 Supengjun. All Rights Reserved. 陕西超拼软件科技有限公司 版权所有,www.cc.chaopin100.com,,粤ICP备2020114798号,粤公网安备44030002001907号';
        $isCopyright = PluginModel::where('name', 'copyright')->value('id');
        if (!$isCopyright) {
            $copyright = request()->scheme() . '://' . request()->host() . '/copyright.png';
            ConfigService::set('applet', 'app_bq', '1,' . $copyright . ',见闻间提供技术支持,www.cc.chaopin100.com,https://cc.chaopin100.com');
            ConfigService::set('system', 'web_bq', $bq);
        }
        $data['copyright'] = explode(',', ConfigService::get('system', 'web_bq', $bq));
        return success($data);
    }


    public function home()
    {
        $data = [];
        return success($data);
    }


    
}
